<template>
  <div class="main-box">
    <TreeFilter
      label="name"
      title="供应商统计列表"
      :data="treeFilterData"
      :default-value="initParam.substationId + ''"
      @change="changeTreeFilter"
    />
    <div class="table-box">
      <div class="card mb10 pt0 pb0">
        <SelectFilter :data="selectFilterData" :default-values="selectFilterValues" @change="changeSelectFilter" />
      </div>
      <ProTable
        ref="proTable"
        title="供应商统计列表"
        highlight-current-row
        :columns="columns"
        :request-api="getSupplierList"
        :init-param="Object.assign(initParam, selectFilterValues)"
      >
        <!-- 表格 header 按钮 -->
        <template #tableHeader>
          <el-button type="primary" :icon="Download" plain @click="downloadFile">导出供应商数据</el-button>
        </template>
        <!-- 单选 -->
        <template #radio="scope">
          <el-radio :label="scope.row.id" v-model="radio"><i></i></el-radio>
        </template>
        <!-- 表格操作 -->
        <template #operation="">
          <el-button type="primary" link :icon="View" @click="openWarehouseDialog">查看详情</el-button>
        </template>
      </ProTable>
      <DetailDrawer ref="detailRef" />
      <WarehouseDialog ref="warehouseRef" />
      <ImportExcel ref="dialogRef" />
    </div>
  </div>
</template>
<script setup lang="tsx" name="useSelectFilter">
import { ref, reactive, onMounted } from "vue";
import { ElMessage } from "element-plus";
import ProTable from "@/components/ProTable/index.vue";
import ImportExcel from "@/components/ImportExcel/index.vue";
import SelectFilter from "@/components/SelectFilter/index.vue";
import { ProTableInstance, ColumnProps } from "@/components/ProTable/interface";
import { Download, View } from "@element-plus/icons-vue";
import { getSupplierList } from "@/api/modules/money";
//import { supplierStatus } from "@/utils/serviceDict";
import DetailDrawer from "./components/DetailDrawer.vue";
import TreeFilter from "@/components/TreeFilter/index.vue";
import WarehouseDialog from "./components/WarehouseDialog.vue";

// 获取 ProTable 元素，调用其获取刷新数据方法（还能获取到当前查询参数，方便导出携带参数）
const proTable = ref<ProTableInstance>();

// 单选
const radio = ref("");

// 表格配置项
const columns: ColumnProps[] = [
  { prop: "supplierId", label: "供应商id", width: 80, search: { el: "input" }, sortable: true },
  { prop: "supplierName", label: "供应商名称", width: 120 },
  { prop: "supplierAddress", label: "供应商地址", width: 120 },
  { prop: "moneyGet", label: "获得金额", width: 150 },
  //{ prop: "paymentType", label: "支付类型", width: 120, sortable: true, tag: true, enum: paymentType },
  { prop: "moneyBack", label: "退回金额", width: 120 },
  { prop: "moneyAccount", label: "总计金额", width: 120 },
  // {
  //   prop: "createTime",
  //   label: "创建时间",
  //   width: 200,
  //   search: {
  //     el: "date-picker",
  //     span: 2,
  //     props: { type: "datetimerange", valueFormat: "YYYY-MM-DD HH:mm:ss" },
  //     defaultValue: ["2022-11-12 11:35:00", "2022-12-12 11:35:00"]
  //   }
  // },
  { prop: "operation", label: "操作", fixed: "right" }
];

// selectFilter 数据
const selectFilterData = reactive([
  {
    title: "日期",
    key: "supplierStatus",
    options: [
      {
        label: "全部",
        value: -1
      },
      {
        label: "一天内",
        value: 0,
        icon: "Box"
      },
      {
        label: "一周内",
        value: 1,
        icon: "SoldOut"
      },
      {
        label: "一月内",
        value: 2,
        icon: "SoldOut"
      }
    ]
  }
]);

// 初始化方法，挂载之后执行的东西填到里面
onMounted(() => {});

const initParam = reactive({ substationId: -1 });

// 默认 selectFilter 参数
const selectFilterValues = ref({ paymentType: -1 });
const changeSelectFilter = (value: typeof selectFilterValues.value) => {
  ElMessage.success("筛选成功 🤔");
  proTable.value!.pageable.current = 1;
  selectFilterValues.value = value;
};

const treeFilterData = ref<any>([]);

// 树形筛选切换
const changeTreeFilter = (val: any) => {
  ElMessage.success("请注意查看请求参数变化 🤔");
  proTable.value!.pageable.current = 1;
  initParam.substationId = val.id;
  // initParam.level = val.level;
};
// 导出任务单列表
const downloadFile = async () => {
  // ElMessageBox.confirm("确认导出数据?", "温馨提示", { type: "warning" }).then(() =>
  //   // useDownload(exportUserInfo, "任务单列表", proTable.value?.searchParam)
  // );
};

// const paymentDetail = (row: Substation.ResPaymentList) => {
//   openDetailDrawer(row);
// };

// const detailRef = ref<InstanceType<typeof DetailDrawer> | null>(null);
// const openDetailDrawer = (row: Partial<Substation.ResPaymentList> = {}) => {
//   const params = {
//     title: "缴款单详情",
//     isView: true,
//     row: { ...row },
//     getTableList: proTable.value?.getTableList
//   };
//   detailRef.value?.acceptParams(params);
// };

const warehouseRef = ref<InstanceType<typeof WarehouseDialog> | null>(null);
const openWarehouseDialog = () => {
  console.log(1324234234234231);
  warehouseRef.value?.open();
};
</script>
